package com.xingyun.kingdee.erp.service.common.enums;

/**
 * @author lingo
 * @version v1.0
 * @date 2019/11/15 10:26
 * @Company www.xyb2b.com
 */

public enum ErpLoginResultCodeEnum {
    DEAL_WITH_FORM(-5, "【管理员登录】需要处理表单"),
    SUCCESS(1, "登录成功"),

    ACTIVATION(-7, "需要激活"),
    ENTRY_CLOUND_UNBIND(-6, "云通行证未绑定Cloud账号"),
    WARNNING(-4, "登录警告"),
    PASSWORD_INVALID_FORCE(-3, "密码验证不通过(强制的)"),
    PASSWORD_INVALID_OPTIONAL(-2, "密码验证不通过(可选的)"),
    FAILURE(-1, "登录失败"),
    ACCOUNT_OR_PASSWORD_WRONG(0, "账号或密码错误"),
    ;

    private final int code;
    private final String reason;

    ErpLoginResultCodeEnum(int code, String reason) {
        this.code = code;
        this.reason = reason;
    }

    public int getCode() {
        return code;
    }

    public String getReason() {
        return reason;
    }

    public static String getReasonByCode(int code) {
        for (ErpLoginResultCodeEnum status : values()) {
            if (status.code == code) {
                return status.reason;
            }
        }
        return String.format("无法找到code为：%d的失败原因", code);
    }


    public static boolean isLoginFail(Integer code) {
        if (code == null) {
            return true;
        }
        return code != ErpLoginResultCodeEnum.SUCCESS.code && code != ErpLoginResultCodeEnum.DEAL_WITH_FORM.code;
    }
}
